package br.ufrj.dcc.smarthotel.controls;

import java.lang.reflect.Type;
import java.util.List;

import br.ufrj.dcc.smarthotel.activities.EventsMenuActivity;
import br.ufrj.dcc.smarthotel.entities.Event;
import br.ufrj.dcc.smarthotel.entities.User;

import com.google.gson.reflect.TypeToken;

public class EventsMenuControl extends Control {
	private EventsMenuActivity activity;
	
	public EventsMenuControl(EventsMenuActivity activity) {
		this.activity = activity;
	}

	@SuppressWarnings("unchecked")
	public void LoadEvents() {
		Type listType = new TypeToken<List<Event>>() {}.getType();
		List<Event> listaEventos = (List<Event>) this.retrieve(this.baseURI + "event", listType);
		
		this.activity.setEventsList(listaEventos);
	}

	@SuppressWarnings("unchecked")
	public int getNumberOfAttendants(Event e) {
		Type listType = new TypeToken<List<User>>() {}.getType();
		List<User> listAttendants = (List<User>) this.retrieve(this.baseURI + "event/" + e.getEventId() + "/user", listType);
		
		if (listAttendants == null) {
			return 0;
		}
		else {
			return listAttendants.size();
		}
	}

}
